package com.mes.cloud.web;

import com.mes.cloud.api.dto.request.product.ProductUnitAddRequest;
import com.mes.cloud.api.dto.request.product.ProductUnitRequest;
import com.mes.cloud.api.dto.request.product.ProductUnitUpdateRequest;
import com.mes.cloud.api.dto.response.ProductUnitDto;
import com.mes.cloud.common.JsonResult;
import com.mes.cloud.service.ProductUnitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author xy
 * @version 2019-08-23 17:43:03
 * @email yuan.xue3@pactera.com
 */
@Api(tags = "产品单位", value = "产品单位接口")
@RestController
@RequestMapping(value = "/productUnit")
public class ProductUnitController  {

    private ProductUnitService productUnitService;

    @Autowired
    public ProductUnitController(ProductUnitService productUnitService) {
        this.productUnitService = productUnitService;
    }


    /**
     * 功能: 产品单位查询所有
     *
     * @param productUnitRequest
     * @return JsonResult<List<ProductUnitDto>>
     */
    @ApiOperation(value = "产品单位查询所有", notes = "产品单位查询所有")
    @PostMapping(value = "/list")
    public JsonResult<List<ProductUnitDto>> list(@Valid @RequestBody ProductUnitRequest productUnitRequest) {
        return productUnitService.list(productUnitRequest);
    }

    /**
     * 功能: 产品单位新增
     *
     * @param productUnitRequest
     * @return JsonResult
     */
    @ApiOperation(value = "产品单位新增", notes = "产品单位新增")
    @PostMapping(value = "/add")
    public JsonResult add(@Valid @RequestBody ProductUnitAddRequest productUnitRequest) {
        return productUnitService.add(productUnitRequest);
    }

    /**
     * 功能: 产品单位修改
     *
     * @param productUnitRequest
     * @return JsonResult
     */
    @ApiOperation(value = "产品单位修改", notes = "产品单位修改")
    @PostMapping(value = "/update")
    public JsonResult update(@Valid @RequestBody ProductUnitUpdateRequest productUnitRequest) {
        return productUnitService.update(productUnitRequest);

    }

    /**
     * 功能: 产品单位查看详情
     *
     * @param id
     * @return JsonResult
     */
    @ApiOperation(value = "产品单位查看详情", notes = "产品单位查看详情")
    @ApiImplicitParam(paramType = "String", name = "id", value = "产品单位主键", required = true)
    @GetMapping(value = "get/{id}")
    public JsonResult<ProductUnitDto> get(@PathVariable String id) {
        return productUnitService.get(id);
    }

}
